package org.soderiakelvy.controller.reparto;

import java.io.Serializable;
import java.util.Map;

import javax.faces.bean.ManagedBean;
import javax.faces.context.FacesContext;

import org.soderiakelvy.controller.util.Constante;
import org.soderiakelvy.model.domain.VehiculoVO;
import org.soderiakelvy.model.service.RepartoServicio;
import org.soderiakelvy.model.service.imp.RepartoServicioImp;

@ManagedBean
public class VehiculoEdit implements Serializable{
	private static final long serialVersionUID = -3096279923240973964L;
	
	private VehiculoVO vehiculo;
	private RepartoServicio service;
	
	//--- CONSTRUCTO ---
	public VehiculoEdit(){
		service  = new RepartoServicioImp();
		FacesContext fc = FacesContext.getCurrentInstance();
		Map<String,Object> sessionParams = fc.getExternalContext().getSessionMap();
		vehiculo = (VehiculoVO) sessionParams.get("vehiculoEdit");
		System.out.println("Vehiculo recibido para editar: "+vehiculo.getMarca());
	}
	
	public String modificarVehiculo(VehiculoVO vehiculo){
		service.updateVehiculo(vehiculo);
		FacesContext fc = FacesContext.getCurrentInstance();
		fc.getExternalContext().getSessionMap().remove("vehiculoEdit");
		return Constante.URL_VEHICULO_LIST;
	}

	public String cancelar(){
		return Constante.URL_VEHICULO_LIST;
	}
	public VehiculoVO getVehiculo() {
		return vehiculo;
	}
	
	public void setVehiculo(VehiculoVO vehiculo) {
		this.vehiculo = vehiculo;
	}
	
}
